<?php defined('BASEPATH') OR exit('No direct script access allowed');


class Admin_model extends Base_model
{
	protected $_table_name = 'admin';
    protected $_key_name = 'id';
	
	public function __construct()
    {
        parent::__construct();
		
    }

    public function lists($limit = NULL,$map_arr = NULL)
    {
        $this->select("admin.id,admin.name,truename,image,email, mobile,status,dept.id as deptId,dept.name as deptName,admin.ctime as Ctime ");
    	$this->join('dept','admin.dept_id = dept.id','left');
    	$this->where('admin.dtime',0);
    	if($this->set_limit($limit))
    	{
    		return $this->result_rows();
    	}
    	else
    	{
    		return $this->result();
    	}
    	
    }
	
	public function login($name = "")
	{
		if(empty($name))
		{
			return false;
		}

        $this->select("id as Id,password as PassWord,name as Name,image as Image,email as Email,ctime as Ctime, utime as Utime,truename as TrueName");

		$this->where('name',$name);
		$this->where('status',1);
		$this->where('dtime',0);
		return $this->row();
	}

    public function adds($data_arr = NULL)
    {
        if($data_arr == NULL) return false;

        $data_arr["ctime"] = time();
        return $this->insert($data_arr);
    }

    public function edit($id = 0,$data_arr = NULL)
    {
        if($id <= 0 || $data_arr == NULL) return false;
        $this->where($this->_key_name,$id);
        $data_arr["utime"] = time();
        return $this->update($data_arr);
    }

    public function dels($ids_arr = NULL)
    {
        if($ids_arr == NULL) return false;
        $this->where_in($this->_key_name,$ids_arr);
        $data_arr['dtime'] = time();
        return $this->update($data_arr);
    }
}
/* End of file base_model.php */
/* Location: ./system/application/models/base_model.php */
